package com.ruoyi.system.controller;

import java.time.LocalDateTime;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.SysEndOrders;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysOrders;
import com.ruoyi.system.service.ISysOrdersService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 订单详情Controller
 * 
 * @author ruoyi
 * @date 2024-10-12
 */
@RestController
@RequestMapping("/system/orders")
public class SysOrdersController extends BaseController
{
    // 临时储存查新出的订单信息
    private List<SysEndOrders> list;
    @Autowired
    private ISysOrdersService sysOrdersService;

    /**
     * 查询订单详情列表
     */
    @PreAuthorize("@ss.hasPermi('system:orders:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysOrders sysOrders)
    {
        /*startPage();*/
        List<SysEndOrders> list = sysOrdersService.selectSysOrdersList(sysOrders);
        return getDataTable(list);
    }

/*    *//**
     * 查询订单详情列表(实时)
     *//*
    @PreAuthorize("@ss.hasPermi('system:orders:list')")
    @GetMapping("/listNow")
    public TableDataInfo listNow(SysOrders sysOrders)
    {
        startPage();
        List<SysEndOrders> list = sysOrdersService.selectSysOrdersList(sysOrders);
        this.list.addAll(list);
        if (this.list.equals(list)){
            return null;
        }
        return getDataTable(list);
    }*/
    /**
     * 导出订单详情列表
     */
    @PreAuthorize("@ss.hasPermi('system:orders:export')")
    @Log(title = "订单详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysOrders sysOrders)
    {
        List<SysEndOrders> list = sysOrdersService.selectSysOrdersList(sysOrders);
        ExcelUtil<SysEndOrders> util = new ExcelUtil<SysEndOrders>(SysEndOrders.class);
        util.exportExcel(response, list, "订单详情数据");
    }

    /**
     * 获取订单详情详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:orders:query')")
    @GetMapping(value = "/{sysOrdersId}")
    public AjaxResult getInfo(@PathVariable("sysOrdersId") Long sysOrdersId)
    {
        return success(sysOrdersService.selectSysOrdersBySysOrdersId(sysOrdersId));
    }

    /**
     * 新增订单详情
     */
    @PreAuthorize("@ss.hasPermi('system:orders:add')")
    @Log(title = "订单详情", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysOrders sysOrders)
    {
        return toAjax(sysOrdersService.insertSysOrders(sysOrders));
    }

    /**
     * 修改订单详情
     */
    @PreAuthorize("@ss.hasPermi('system:orders:edit')")
    @Log(title = "订单详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysOrders sysOrders)
    {
        return toAjax(sysOrdersService.updateSysOrders(sysOrders));
    }

    /**
     * 修改出单状态
     */
    @PreAuthorize("@ss.hasPermi('system:orders:edit')")
    @Log(title = "订单详情", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody SysOrders sysOrders)
    {
        sysOrders.setOrdersUpdateTime(LocalDateTime.now());
        return toAjax(sysOrdersService.updateSysOrders(sysOrders));
    }

    /**
     * 删除订单详情
     */
    @PreAuthorize("@ss.hasPermi('system:orders:remove')")
    @Log(title = "订单详情", businessType = BusinessType.DELETE)
	@DeleteMapping("/{sysOrdersIds}")
    public AjaxResult remove(@PathVariable Long[] sysOrdersIds)
    {
        return toAjax(sysOrdersService.deleteSysOrdersBySysOrdersIds(sysOrdersIds));
    }
}
